<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class A_jabatan extends CI_Controller {

	function __construct() {
        parent::__construct();	
		$this->load->model("master/master_jabatan"); 
		$this->load->model("atur/atur_jabatan"); 
	}
	
	function index()
	{
		$this->load->helper('selisihtgl'); 
		$data['judul'] = "Pengaturan Jabatan";
		$data['list'] = $this->atur_jabatan->udah_diatur();
		$data['list_j'] = $this->atur_jabatan->blm_diatur();
		$data['main_view']='atur/jabatan/jabatan';
		$this->load->view('index',$data);		
	}

	function edit()
	{
		$id_a_jabatan = $this->input->post('id_a_jabatan');
		$data['list']=$this->atur_jabatan->edit($id_a_jabatan);
		$data['list_p']=$this->atur_jabatan->pegawai_no_jabatan($id_a_jabatan);
		$this->load->view('atur/jabatan/edit',$data);
	}

	function update()
	{	
		$id_a_jabatan=$this->input->post('id_a_jabatan');

		$mulai = $this->input->post('mulai');
		$dateMulai = str_replace('/', '-', $mulai);
		$tglMySQLM = date('Y-m-d', strtotime($dateMulai));

		$akhir = $this->input->post('akhir');
		$dateAkhir = str_replace('/', '-', $akhir);
		$tglMySQLA = date('Y-m-d', strtotime($dateAkhir));

		$dataUpdate=array(
			'id_m_pegawai'=>$this->input->post('id_m_pegawai'),
			'mulai'=>$tglMySQLM,
			'akhir'=>$tglMySQLA.' 23:59:59'
		);		
		$this->atur_jabatan->update($id_a_jabatan,$dataUpdate);
	}

	function save()
	{
		$mulai = $this->input->post('mulai');
		$dateMulai = str_replace('/', '-', $mulai);
		$tglMySQLM = date('Y-m-d', strtotime($dateMulai));

		$akhir = $this->input->post('akhir');
		$dateAkhir = str_replace('/', '-', $akhir);
		$tglMySQLA = date('Y-m-d', strtotime($dateAkhir));

		$dataInsert = array(
			'id_m_pegawai'=>$this->input->post('id_m_pegawai'),
			'id_m_jabatan'=>$this->input->post('id_m_jabatan'),
			'mulai'=>$tglMySQLM,
			'akhir'=>$tglMySQLA
		);
		$this->atur_jabatan->save($dataInsert);
	}	

	function atur()
	{
		$id_m_jabatan = $this->input->post('id_m_jabatan');
		$data['list_j']=$this->master_jabatan->edit($id_m_jabatan);
		$data['list_p']=$this->atur_jabatan->pegawai_no_jabatan2();
		$this->load->view('atur/jabatan/atur',$data);
	}

	function refresh()
	{
		$this->load->helper('selisihtgl');
		$data['list'] = $this->atur_jabatan->udah_diatur();
		$data['list_j'] = $this->atur_jabatan->blm_diatur();
		$this->load->view('atur/jabatan/refresh', $data);		
	}
	
}